package com.shunda.trade.controller;

import com.shunda.common.core.controller.BaseController;
import com.shunda.common.core.page.TableDataInfo;
import com.shunda.trade.entity.TradeWithdrawalsFlow;
import com.shunda.trade.service.TradeWithdrawalsFlowService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 用户信息表(TradeWithdrawalsFlow)表控制层
 *
 * @author makejava
 * @since 2025-03-13 21:36:54
 */
@RestController
@RequestMapping("tradeWithdrawalsFlow")
public class TradeWithdrawalsFlowController extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private TradeWithdrawalsFlowService tradeWithdrawalsFlowService;

    /**
     * 分页查询
     *
     * @param tradeWithdrawalsFlow 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @GetMapping
    public ResponseEntity<Page<TradeWithdrawalsFlow>> queryByPage(TradeWithdrawalsFlow tradeWithdrawalsFlow, PageRequest pageRequest) {
        return ResponseEntity.ok(this.tradeWithdrawalsFlowService.queryByPage(tradeWithdrawalsFlow, pageRequest));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<TradeWithdrawalsFlow> queryById(@PathVariable("id") Long id) {
        return ResponseEntity.ok(this.tradeWithdrawalsFlowService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param tradeWithdrawalsFlow 实体
     * @return 新增结果
     */
    @PostMapping
    public ResponseEntity<TradeWithdrawalsFlow> add(TradeWithdrawalsFlow tradeWithdrawalsFlow) {
        return ResponseEntity.ok(this.tradeWithdrawalsFlowService.insert(tradeWithdrawalsFlow));
    }

    /**
     * 编辑数据
     *
     * @param tradeWithdrawalsFlow 实体
     * @return 编辑结果
     */
    @PutMapping
    public ResponseEntity<TradeWithdrawalsFlow> edit(TradeWithdrawalsFlow tradeWithdrawalsFlow) {
        return ResponseEntity.ok(this.tradeWithdrawalsFlowService.update(tradeWithdrawalsFlow));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public ResponseEntity<Boolean> deleteById(Long id) {
        return ResponseEntity.ok(this.tradeWithdrawalsFlowService.deleteById(id));
    }

    public TableDataInfo getWithdrawFlowPage(TradeWithdrawalsFlow withdrawalsFlow) {
        startPage();
        List<TradeWithdrawalsFlow> list = tradeWithdrawalsFlowService.selectWithdrawFlowPage(withdrawalsFlow);
        return getDataTable(list);
    }
}

